#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {
        int n = tops.size();
        int a = 0, b = 0, c = 0, d = 0;
        for (int i = 1; i < n; ++i) {
            if (tops[i] == tops[0]) continue;
            else if (bottoms[i] == tops[0]) ++a;
            else {
                a = INT_MAX;
                break;
            }
        }
        for (int i = 1; i < n; ++i) {
            if (bottoms[i] == bottoms[0]) continue;
            else if (tops[i] == bottoms[0]) ++b;
            else {
                b = INT_MAX;
                break;
            }
        }
        for (int i = 0; i < n; ++i) {
            if (tops[i] == bottoms[0]) continue;
            else if (bottoms[i] == bottoms[0]) ++c;
            else {
                c = INT_MAX;
                break;
            }
        }
        for (int i = 0; i < n; ++i) {
            if (bottoms[i] == tops[0]) continue;
            else if (tops[i] == tops[0]) ++d;
            else {
                d = INT_MAX;
                break;
            }
        }
        int ans = min(min(a, b), min(c, d));
        return ans == INT_MAX ? -1 : ans;
    }
};
int main()
{
	return 0;
}